package com.mxue.test;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileAttributeView;
import java.util.Objects;
import java.util.Scanner;

public class FileDemo {
    public static void main(String[] args) throws IOException {



        FileInputStream fileInputStream = new FileInputStream("/Users/wangyexin/study/golang/wintogether-tools/service/wintogether/tmp/TestSendCoupon.log");

        FileReader fileReader = new FileReader("/Users/wangyexin/study/golang/wintogether-tools/service/wintogether/tmp/TestSendCoupon.log");
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("/Users/wangyexin/study/golang/wintogether-tools/service/wintogether/tmp/TestSendCoupon3.log"));


        BufferedReader bufferedReader = new BufferedReader(fileReader);

        while (true) {
            String txt = bufferedReader.readLine();

            if (Objects.isNull(txt)) {
                break;
            }

            System.out.println(txt);
            bufferedWriter.write(txt + "\r\n");
        }



        /*==========读取写入文件=========*/

        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);

        FileOutputStream fileOutputStream = new FileOutputStream("/Users/wangyexin/study/golang/wintogether-tools/service/wintogether/tmp/TestSendCoupon2.log");


        Scanner scanner = new Scanner(fileInputStream);

        while (scanner.hasNext()) {
//            System.out.println(scanner.next());

            fileOutputStream.write(scanner.next().getBytes(StandardCharsets.UTF_8));
            fileOutputStream.write("\n".getBytes(StandardCharsets.UTF_8));
        }


        bufferedWriter.close();

        Files.createDirectories(Paths.get("/Users/wangyexin/study/golang/wintogether-tools2"));
    }
}
